package com.ibm.st.talent.update.profile.status;

/*
 * Licensed Materials - Property of IBM
 *
 * L-KBIM-82KJL8
 *
 * (C) Copyright IBM Corp. 2006, 2010. All rights reserved.
 *
 * US Government Users Restricted Rights- Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 */

import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

/**
 * Shows how to add a basic QuickFindWidget to a Dialog
 */

public class AuthenticationDialog extends TitleAreaDialog {

	private Text password;
	
	private String pwd;

	public AuthenticationDialog(Shell shell) {
		super(shell);
	}

	protected void configureShell(Shell shell) {
		super.configureShell(shell);
		shell.setText("Your Intranet Password");
		shell.setSize(450, 200);
	}

	protected Control createDialogArea(Composite parent) {

		this.setMessage("Please input your intranet password for the first time to update status after Sametime Client started up.",
						IMessageProvider.WARNING);

		Composite c = new Composite(parent, SWT.CENTER);
		
		FormLayout layout = new FormLayout();
		layout.marginWidth = layout.marginHeight = 20;
		c.setLayout(layout);

		password = new Text(c, SWT.PASSWORD | SWT.BORDER);

		int columns = 60;
		int lines = 1;
		GC gc = new GC(password);
		FontMetrics fm = gc.getFontMetrics();

		int width = columns * fm.getAverageCharWidth();
		int height = lines * password.getLineHeight();

		FormData data = new FormData(width, height);
		password.setLayoutData(data);
		password.setFocus();
		
		return c;
	}

	@Override
	protected void cancelPressed() {
		pwd = password.getText();
		super.cancelPressed();
	}

	public String getPwd() {
		return pwd;
	}

	@Override
	protected void okPressed() {
		pwd = password.getText();
		super.okPressed();
	}
	
	protected void initializeBounds() {
		super.initializeBounds();
		Shell shell = this.getShell();
		Monitor primary = shell.getMonitor();
		Rectangle bounds = primary.getBounds();
		Rectangle rect = shell.getBounds();
		int x = bounds.x + (bounds.width - rect.width) / 2;
		int y = bounds.y + (bounds.height - rect.height) / 2;
		shell.setLocation(x, y);
	}
}
